//
//  BaseCollectionView.m
//  TakeYouTourTogether
//
//  Created by king on 15/11/26.
//  Copyright © 2015年 king. All rights reserved.
//

#import "BaseCollectionView.h"

@implementation BaseCollectionView
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"test" object:nil];
}

#pragma mark - Method initWithFrame:collectionViewLayout:
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout {
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        [self createCollectionView];
    }
    return self;
}
#pragma mark - Method createCollectionView
- (void)createCollectionView {
    self.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [self isDayOrNight];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backValue:) name:@"test" object:nil];

}

#pragma mark - Method isDayOrNight
- (UIColor *)isDayOrNight {
    return [NightTimeModel shareNightTimeModel].isDayOrNight ? [UIColor whiteColor] :[UIColor blackColor];
}
#pragma mark - Method 通知中心
- (void)backValue:(NSNotification *)notification {
    BOOL b = [notification.userInfo[@"1"] boolValue];
    if (b) {
        [NightTimeModel shareNightTimeModel].isDayOrNight = NO;
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isDayOrNight"];
        self.backgroundColor = [UIColor blackColor];
    } else {
        [NightTimeModel shareNightTimeModel].isDayOrNight = YES;
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isDayOrNight"];
        self.backgroundColor = [UIColor whiteColor];
    }
}

@end
